package com.xncoding.easypoi.controller;


import cn.afterturn.easypoi.entity.vo.BigExcelConstants;
import cn.afterturn.easypoi.entity.vo.NormalExcelConstants;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
import cn.afterturn.easypoi.excel.entity.vo.BaseEntityTypeConstants;
import cn.afterturn.easypoi.excel.export.ExcelExportService;
import cn.afterturn.easypoi.exception.excel.ExcelExportException;
import cn.afterturn.easypoi.exception.excel.enums.ExcelExportEnum;
import cn.afterturn.easypoi.handler.inter.IExcelExportServer;
import cn.afterturn.easypoi.handler.inter.IWriter;
import cn.afterturn.easypoi.util.PoiCellUtil;
import cn.afterturn.easypoi.view.EasypoiSingleExcelView;
import cn.afterturn.easypoi.view.PoiBaseView;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xncoding.easypoi.model.*;
import com.xncoding.easypoi.service.ExcelVerifyHandlerImpl;
import com.xncoding.easypoi.util.ExcelConvert;
import com.xncoding.easypoi.util.ExcelUtils;
import com.xncoding.easypoi.util.PDFUtils;
import com.xncoding.easypoi.util.PoiUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.formula.functions.T;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.util.*;
import java.util.concurrent.ConcurrentMap;
import java.util.stream.Collectors;

@RestController
public class IndexController {

    private static final Logger _logger = LoggerFactory.getLogger(IndexController.class);

    private String filePath = System.getProperty("user.dir");
    private String path = Thread.currentThread().getContextClassLoader().getResource("").getPath()+"template";

    @Autowired
    private ExportLoadDataHandler excelExportServer;

    /**
     * 主页
     *
     * @param model
     * @return
     */
//    @RequestMapping({"/", "/index"})
    public ModelAndView index(ModelAndView model) {
        model.addObject("msg", "welcome211啊啊e you!");
        model.setViewName("index");
        return model;
    }

    @RequestMapping({"/test01"})
    public String test(ModelAndView model) {
        return "1111";
    }

    /**
     * 导出excel，
     * 通过注解的形式
     * 带图片
     * @param request
     * @param response
     * @throws Exception
     */
    @RequestMapping("expoetJavaBeanXls")
    public void expoetXls(HttpServletRequest request, HttpServletResponse response) throws Exception {
        // 告诉浏览器用什么软件可以打开此文件
        response.setHeader("content-Type", "application/vnd.ms-excel");
        // 下载文件的默认名称
        response.setHeader("Content-Disposition", "attachment;filename=ReMianPage.xls");
        List<ReMianPage> list = new ArrayList<>();
        ReMianPage mg01 = new ReMianPage();
        mg01.setXm("张坤");
        mg01.setXb("男");
        mg01.setCsny(new Date());
        ReMianPage mg02 = new ReMianPage();
        mg02.setXm("张坤");
        mg02.setXb("男");
        mg02.setCsny(new Date());
        mg02.setZp("D:/java/workspace/idea/springboot-bucket/springboot-easypoi/src/main/resources/template/123.png");
        list.add(mg01);
        list.add(mg02);
        if (true){
            throw new RuntimeException("1111");
        }
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), ReMianPage.class, list);
        workbook.write(response.getOutputStream());
    }

    /**
     * 导出excel，
     * 通过注解的形式
     * 一对多
     * 带图片
     * @param request
     * @param response
     * @throws Exception
     */
    @RequestMapping("expoeOneToManyetXls")
    public void expoeOneToManyetXls(HttpServletRequest request, HttpServletResponse response) throws Exception {
        // 告诉浏览器用什么软件可以打开此文件
        response.setHeader("content-Type", "application/vnd.ms-excel");
        // 下载文件的默认名称
        response.setHeader("Content-Disposition", "attachment;filename=ReMianPage.xls");
        List<StudentEntity> list = new ArrayList<>();
        StudentEntity mg01 = new StudentEntity();
        mg01.setName("张坤");
        mg01.setSex(1);
        mg01.setBirthday(new Date());
        StudentEntity mg02 = new StudentEntity();
        mg02.setName("张坤");
        mg02.setSex(1);
        mg02.setBirthday(new Date());
        mg02.setZp("D:/java/workspace/idea/springboot-bucket/springboot-easypoi/src/main/resources/template/123.png");
        list.add(mg01);
        list.add(mg02);

        TeacherEntity te01 = new TeacherEntity();
        te01.setName("absent");

        CourseEntity co01 = new CourseEntity();
        co01.setName("shuxue");
        co01.setMathTeacher(te01);
        co01.setStudents(list);

        List<CourseEntity> list1 = new ArrayList<CourseEntity>();
        list1.add(co01);
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("2412312", "测试", "测试"), CourseEntity.class, list1);
        workbook.write(response.getOutputStream());
    }

    /**
     * 变种注解
     * 代码注解导出
     * @param request
     * @param response
     * @throws Exception
     */
    @RequestMapping("expoetXls01")
    public void expoetXls01(HttpServletRequest request, HttpServletResponse response) throws Exception {
        // 告诉浏览器用什么软件可以打开此文件
        response.setHeader("content-Type", "application/vnd.ms-excel");
        // 下载文件的默认名称
        response.setHeader("Content-Disposition", "attachment;filename=ReMianPage.xls");
        List<ExcelExportEntity> entity = new ArrayList<ExcelExportEntity>();//构造对象等同于@Excel

        entity.add(new ExcelExportEntity("性别", "sex"));
        entity.add(new ExcelExportEntity("姓名", "name"));

        ExcelExportEntity headImage = new ExcelExportEntity("图像", "HeadImage");
        //此处是设置图片
        headImage.setExportImageType(1);  //设置导出图片类型是文件
        headImage.setType(BaseEntityTypeConstants.IMAGE_TYPE);  //设置类型是图片
        entity.add(headImage);

        List<Map<String, String>> list = new ArrayList<Map<String, String>>();
        Map<String,String> h1 = new HashMap<String,String>();
        h1.put("name", "你大爷");
        h1.put("sex", "男");
        Map<String,String> h2 = new HashMap<String,String>();
        h2.put("name", "你打奶");
        h2.put("sex", "女");
        h2.put("HeadImage", "D:/java/workspace/idea/springboot-bucket/springboot-easypoi/src/main/resources/template/123.png");

        list.add(h1);
        list.add(h2);
        //把我们构造好的bean对象放到params就可以了
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("测试11", "测试22"), entity, list);
//        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("2412312", "测试", "测试"), CourseEntity.class, list1);
        workbook.write(response.getOutputStream());
    }

    @RequestMapping("expoeMoreSheet")
    public void expoeMoreSheet(HttpServletRequest request, HttpServletResponse response) throws Exception {
// 告诉浏览器用什么软件可以打开此文件
        response.setHeader("content-Type", "application/vnd.ms-excel");
        // 下载文件的默认名称
        response.setHeader("Content-Disposition", "attachment;filename=ReMianPage.xls");
        List<ReMianPage> list = new ArrayList<>();
        ReMianPage mg01 = new ReMianPage();
        mg01.setXm("张坤");
        mg01.setXb("男");
        mg01.setCsny(new Date());
        ReMianPage mg02 = new ReMianPage();
        mg02.setXm("张坤");
        mg02.setXb("男");
        mg02.setCsny(new Date());
        mg02.setZp("D:/java/workspace/idea/springboot-bucket/springboot-easypoi/src/main/resources/template/123.png");
        list.add(mg01);
        list.add(mg02);

        List<ReMianPage> list1 = new ArrayList<>();
        ReMianPage mg03 = new ReMianPage();
        mg03.setXm("张坤");
        mg03.setXb("男");
        mg03.setCsny(new Date());
        ReMianPage mg04 = new ReMianPage();
        mg04.setXm("张坤");
        mg04.setXb("男");
        mg04.setCsny(new Date());
        mg04.setZp("D:/java/workspace/idea/springboot-bucket/springboot-easypoi/src/main/resources/template/123.png");
        list1.add(mg03);
        list1.add(mg04);


        // sheet1设置
        Map<String, Object> sheet1ExportMap = new HashMap<>();
        sheet1ExportMap.put(NormalExcelConstants.CLASS, ReMianPage.class);
        sheet1ExportMap.put(NormalExcelConstants.DATA_LIST, list);
        sheet1ExportMap.put(NormalExcelConstants.PARAMS, new ExportParams("遥信表", "遥信"));
        //这边为了方便，sheet1和sheet2用同一个表头(实际使用中可自行调整)
//        sheet1ExportMap.put(NormalExcelConstants.MAP_LIST, ReMianPage.class);

        //Sheet2设置
        Map<String, Object> sheet2ExportMap = new HashMap<>();
        sheet2ExportMap.put(NormalExcelConstants.CLASS, ReMianPage.class);
        sheet2ExportMap.put(NormalExcelConstants.DATA_LIST, list1);
        sheet2ExportMap.put(NormalExcelConstants.PARAMS, new ExportParams("遥测表", "遥测"));
        //这边为了方便，sheet1和sheet2用同一个表头(实际使用中可自行调整)
//        sheet2ExportMap.put(NormalExcelConstants.MAP_LIST, ReMianPage.class);

        // 将sheet1、sheet2使用得map进行包装
        List<Map<String, Object>> sheetsList = new ArrayList<>();
        sheetsList.add(sheet1ExportMap);
        sheetsList.add(sheet2ExportMap);
        Workbook workbook = new HSSFWorkbook();
        for(Map<String,Object> map : sheetsList) {
            ExcelExportService server = new ExcelExportService();
            ExportParams param = (ExportParams) map.get("params");
            Class<ReMianPage> entity = (Class<ReMianPage>) map.get("entity");
            Collection<?> data = (Collection<?>) map.get("data");
            server.createSheet(workbook, param, entity, data);
        }

        workbook.write(response.getOutputStream());
    }

    @RequestMapping("expoeMoreSheet01")
    public void expoeMoreSheet01(HttpServletRequest request, HttpServletResponse response) throws Exception {

        // 告诉浏览器用什么软件可以打开此文件
        response.setHeader("content-Type", "application/vnd.ms-excel");
        // 下载文件的默认名称
        response.setHeader("Content-Disposition", "attachment;filename=ReMianPage.xls");
        List<ExcelExportEntity> entity = new ArrayList<ExcelExportEntity>();//构造对象等同于@Excel

        entity.add(new ExcelExportEntity("性别", "sex"));
        entity.add(new ExcelExportEntity("姓名", "name"));

        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        Map<String,Object> h1 = new HashMap<String,Object>();
        h1.put("name", "你大爷");
        h1.put("sex", "男");
        Map<String,Object> h2 = new HashMap<String,Object>();
        h2.put("name", "你打奶");
        h2.put("sex", "女");
        list.add(h1);
        list.add(h2);

        List<Map<String, Object>> list1 = new ArrayList<Map<String, Object>>();
        Map<String,Object> h3 = new HashMap<String,Object>();
        h3.put("name", "你大爷");
        h3.put("sex", "男");
        Map<String,Object> h4 = new HashMap<String,Object>();
        h4.put("name", "你打奶");
        h4.put("sex", "女");
        list1.add(h3);
        list1.add(h4);

        // sheet1设置
        Map<String, Object> sheet1ExportMap = new HashMap<>();
        sheet1ExportMap.put(NormalExcelConstants.CLASS, ExcelExportEntity.class);
        sheet1ExportMap.put(NormalExcelConstants.DATA_LIST, list);
        sheet1ExportMap.put(NormalExcelConstants.PARAMS, new ExportParams("遥信表", "遥信"));
        //这边为了方便，sheet1和sheet2用同一个表头(实际使用中可自行调整)
        sheet1ExportMap.put(NormalExcelConstants.MAP_LIST, entity);

        //Sheet2设置
        Map<String, Object> sheet2ExportMap = new HashMap<>();
        sheet2ExportMap.put(NormalExcelConstants.CLASS, ExcelExportEntity.class);
        sheet2ExportMap.put(NormalExcelConstants.DATA_LIST, list1);
        sheet2ExportMap.put(NormalExcelConstants.PARAMS, new ExportParams("遥测表", "遥测"));
        //这边为了方便，sheet1和sheet2用同一个表头(实际使用中可自行调整)
        sheet2ExportMap.put(NormalExcelConstants.MAP_LIST, entity);

        // 将sheet1、sheet2使用得map进行包装
        List<Map<String, Object>> sheetsList = new ArrayList<>();
        sheetsList.add(sheet1ExportMap);
        sheetsList.add(sheet2ExportMap);
        Workbook workbook = new HSSFWorkbook();
        for(Map<String,Object> map : sheetsList) {
            ExcelExportService server = new ExcelExportService();
            ExportParams param = (ExportParams) map.get("params");
            @SuppressWarnings("unchecked")
            List<ExcelExportEntity> mapList = (List<ExcelExportEntity>) map.get("mapList");
            Collection<?> data = (Collection<?>) map.get("data");
            server.createSheetForMap(workbook, param, entity, data);
        }

        //把我们构造好的bean对象放到params就可以了
//        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("测试11", "测试22"), entity,
//                list);
        workbook.write(response.getOutputStream());
    }

    @RequestMapping("expoetXls02")
    public void expoetXls02(HttpServletRequest request, HttpServletResponse response) throws Exception {
        List<ReMianPage> list = new ArrayList<>();
        ReMianPage mg01 = new ReMianPage();
        mg01.setXm("张坤");
        mg01.setXb("男");
        mg01.setCsny(new Date());
        ReMianPage mg02 = new ReMianPage();
        mg02.setXm("张坤");
        mg02.setXb("男");
        mg02.setCsny(new Date());
        mg02.setZp("D:/java/workspace/idea/springboot-bucket/springboot-easypoi/src/main/resources/template/123.png");
        list.add(mg01);
        list.add(mg02);
        Map map = new HashMap();
        ExportParams params = new ExportParams("2412312", "测试", ExcelType.XSSF);
//        params.setFreezeCol(2);
        map.put(NormalExcelConstants.DATA_LIST, list);
        map.put(NormalExcelConstants.CLASS, ReMianPage.class);
        map.put(NormalExcelConstants.FILE_NAME, "1101");
        map.put(NormalExcelConstants.PARAMS, params);
        PoiBaseView.render(map,request,response,NormalExcelConstants.EASYPOI_EXCEL_VIEW);
//        return NormalExcelConstants.EASYPOI_EXCEL_VIEW;
    }
    @RequestMapping("expoetXls03")
    public String expoetXls03(ModelMap modelMap) throws Exception {
        List<ReMianPage> list = new ArrayList<>();
        ReMianPage mg01 = new ReMianPage();
        mg01.setXm("张坤");
        mg01.setXb("男");
        mg01.setCsny(new Date());
        ReMianPage mg02 = new ReMianPage();
        mg02.setXm("张坤");
        mg02.setXb("男");
        mg02.setCsny(new Date());
        mg02.setZp("D:/java/workspace/idea/springboot-bucket/springboot-easypoi/src/main/resources/template/123.png");
        list.add(mg01);
        list.add(mg02);
        ExportParams params = new ExportParams("2412312", "测试", ExcelType.XSSF);
//        params.setFreezeCol(2);
//        ModelAndView modelMap = new ModelAndView(new EasypoiSingleExcelView());
        modelMap.put(NormalExcelConstants.DATA_LIST, list);
        modelMap.put(NormalExcelConstants.CLASS, ReMianPage.class);
        modelMap.put(NormalExcelConstants.FILE_NAME, "1101");
        modelMap.put(NormalExcelConstants.PARAMS, params);
        modelMap.put(NormalExcelConstants.EASYPOI_EXCEL_VIEW, new EasypoiSingleExcelView());
//        PoiBaseView.render(map,request,response,NormalExcelConstants.EASYPOI_EXCEL_VIEW);
        return NormalExcelConstants.EASYPOI_EXCEL_VIEW;
    }

    @RequestMapping("/upload")
    public Boolean upload(HttpServletRequest request, HttpServletResponse response) throws Exception {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
            MultipartFile file = entity.getValue();// 获取上传文件对象
            ImportParams params = new ImportParams();
//            params.setTitleRows(2);
            params.setHeadRows(1);
            params.setNeedSave(true);
            List<ReMianPage> listAsds = ExcelImportUtil.importExcel(file.getInputStream(), ReMianPage.class, params);
            _logger.info(JSON.toJSONString(listAsds));
        }
        return true;
    }

    /**
     * map导入
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("/uploadMap")
    public String uploadMap(HttpServletRequest request, HttpServletResponse response) throws Exception {

        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        List<Map<String, Object>> list = null;
        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
            List<Map<String, Object>> listAsds = null;
            try{
                MultipartFile file = entity.getValue();// 获取上传文件对象
                ImportParams params = new ImportParams();
//                params.setDataHandler(new MapImportHandler());
//                params.setVerifyHandler(new ExcelVerifyHandlerImpl());
                params.setTitleRows(2);
//            params.setHeadRows(1);
//                params.setNeedSave(true);
//                ExcelImportResult<List<Map<String, Object>>> result
                listAsds =  ExcelImportUtil.importExcel(file.getInputStream(), Map.class, params);
                _logger.info(JSON.toJSONString(listAsds));
            }catch (Exception e){
                e.printStackTrace();
            }

            list = listAsds.stream().filter(map->{
                JSONObject res = JSONObject.parseObject(JSON.toJSONString(map));;
                return res.size()>1;
            }).collect(Collectors.toList());
            _logger.info(JSON.toJSONString(listAsds));
        }
        _logger.info("----------------------------------");
        List<Map<String, Object>> listAsds0 = list;
        _logger.info(JSON.toJSONString(list));
        return JSON.toJSONString(listAsds0);
    }

    /**
     * map导入，获取返回指定行报错信息
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("/uploadMap01")
    public String uploadMap01(HttpServletRequest request, HttpServletResponse response) throws Exception {

        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        List<Map<String, Object>> list = null;
        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
            List<Map<String, Object>> listAsds = null;
            List<Map<String, Object>> listerr = null;
            try{
                MultipartFile file = entity.getValue();// 获取上传文件对象
                ImportParams params = new ImportParams();
                params.setDataHandler(new MapImportHandler());
                params.setVerifyHandler(new ExcelVerifyHandlerImpl());
                params.setTitleRows(2);
//            params.setHeadRows(1);
//                params.setNeedSave(true);
//                ExcelImportResult<Map<String, Object>> result =  ExcelImportUtil.importExcelMore(file.getInputStream(), Map.class, params);
                ExcelImportResult<Map<String, Object>> result =  ExcelImportUtil.importExcelMore(file.getInputStream(), Map.class, params);
                listAsds = result.getList();
                listerr = result.getFailList();
                _logger.info("suc"+JSON.toJSONString(listAsds));
                _logger.info("err"+JSON.toJSONString(listerr));
            }catch (Exception e){
                e.printStackTrace();
            }

            /*list = listAsds.stream().filter(map->{
                JSONObject res = JSONObject.parseObject(JSON.toJSONString(map));;
                return res.size()>1;
            }).collect(Collectors.toList());*/
            _logger.info(JSON.toJSONString(listAsds));
        }
        _logger.info("----------------------------------");
        List<Map<String, Object>> listAsds0 = list;
        _logger.info(JSON.toJSONString(list));
        return JSON.toJSONString(listAsds0);
    }

    /**
     * map导入，获取返回指定行报错信息
     * 读取指定行
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("/uploadMap02")
    public String uploadMap02(HttpServletRequest request, HttpServletResponse response) throws Exception {

        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        List<Map<String, Object>> list = null;
        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
            List<Map<String, Object>> listAsds = null;
            List<Map<String, Object>> listerr = null;
            try{
                MultipartFile file = entity.getValue();// 获取上传文件对象
                ImportParams params = new ImportParams();
                params.setDataHandler(new MapImportHandler());
                params.setVerifyHandler(new ExcelVerifyHandlerImpl());
                params.setTitleRows(2);
//            params.setHeadRows(1);
//                params.setNeedSave(true);
                ExcelImportResult<Map<String, Object>> result =  ExcelImportUtil.importExcelMore(file.getInputStream(), Map.class, params);
                listAsds = result.getList();
                listerr = result.getFailList();
                _logger.info("suc"+JSON.toJSONString(listAsds));
                _logger.info("err"+JSON.toJSONString(listerr));
                PoiUtils.getCell(file,0,1,2);
                PoiUtils.getCell(file,0,1,4);

            }catch (Exception e){
                e.printStackTrace();
            }

            /*list = listAsds.stream().filter(map->{
                JSONObject res = JSONObject.parseObject(JSON.toJSONString(map));;
                return res.size()>1;
            }).collect(Collectors.toList());*/
            _logger.info(JSON.toJSONString(listAsds));
        }
        _logger.info("----------------------------------");
        List<Map<String, Object>> listAsds0 = list;
        _logger.info(JSON.toJSONString(list));
        return JSON.toJSONString(listAsds0);
    }
    /**
     * 无固定列导入
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("/uploadMap03")
    public String uploadMap03(HttpServletRequest request, HttpServletResponse response) throws Exception {
        List<AlarmObj01> alarmObjs = new ArrayList<>();
        Map<String, String> fieldMap = new HashMap<>();
        fieldMap.put("1","b");
        fieldMap.put("2","c");
        fieldMap.put("3","d");
        fieldMap.put("4","e");
        fieldMap.put("5","f");
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        ExcelImportResult<ObjTets> result = null;
        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
            MultipartFile file = entity.getValue();// 获取上传文件对象
            ImportParams params = new ImportParams();
//            ObjImportHandler hanlder = new ObjImportHandler();
//            hanlder.setNeedHandlerFields(new String[] { "FIXED_0","FIXED_1","FIXED_2" });
//            params.setDataHandler(hanlder);
//            params.setVerifyHandler(new ExcelVerifyHandlerImpl());
            params.setTitleRows(2);
            result = ExcelImportUtil.importExcelMore(file.getInputStream(), AlarmObj01.class, params);
        }
//        alarmObjs = result.getList();
        System.out.println(JSON.toJSONString(result.getList()));

        for (AlarmObj01 alarmObj : alarmObjs) {
            try{
                ExcelConvert.convertInput(alarmObj,fieldMap);
            } catch (Exception e) {
                throw new ExcelExportException(ExcelExportEnum.TEMPLATE_ERROR,e); //模板导出有误
            }
        }

        System.out.println(JSON.toJSONString(alarmObjs));


        return null;
    }
    @RequestMapping("/uploadMap04")
    public String uploadMap04(HttpServletRequest request, HttpServletResponse response) throws Exception {
        Class pojoClass = new AlarmObj01().getClass();
        List alarmObjsList = new ArrayList<AlarmObj01>();

        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
        JSONObject obj = null;
        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
            MultipartFile file = entity.getValue();// 获取上传文件对象
            obj = ExcelUtils.importTetsExcel(file,2,1,true,pojoClass);
            System.out.println(obj.toJSONString());

            alarmObjsList = JSONObject.parseArray(obj.getJSONArray("err").toJSONString(),pojoClass);
            System.out.println("-----------------------");
            System.out.println(JSON.toJSONString(alarmObjsList));
        }
        ExcelOut out = new ExcelOut();

        out.setErrList(alarmObjsList);
        System.out.println("-----------------------");
        System.out.println(JSON.toJSONString(out));

        return null;
    }
    @RequestMapping("/uploadMap05")
    public String uploadMap05(HttpServletRequest request, HttpServletResponse response) throws Exception {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        Class pojoClass = new AlarmObj01().getClass();
        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
            MultipartFile file = entity.getValue();// 获取上传文件对象
            ExcelImportResult<Object> result = ExcelUtils.importTetsExcelObj(file,2,1,true,pojoClass);

            System.out.println(JSON.toJSONString(result.getFailList()));
            System.out.println(JSON.toJSONString(result.getList()));
            System.out.println("---------------");
            ExcelOut out = new ExcelOut();
            out.setOerrList(result.getFailList());
            System.out.println(JSON.toJSONString(out));

            PoiUtils.getrow(file);

        }



        return null;
    }


    /**
     * 大数据导出
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("/bigDataExport")
    public void bigDataExport(HttpServletRequest request, HttpServletResponse response) throws Exception {
        // 告诉浏览器用什么软件可以打开此文件
        response.setHeader("content-Type", "application/vnd.ms-excel");
        // 下载文件的默认名称
        response.setHeader("Content-Disposition", "attachment;filename=bigDataExport.xlsx");

        Workbook workbook = new HSSFWorkbook();
        Date start = new Date();
        ExportParams params = new ExportParams();

        workbook = ExcelExportUtil.exportBigExcel(params, ReMianPage.class, new IExcelExportServer() {
            @Override
            public List<Object> selectListForExcelExport(Object obj, int page) {
                if (((int) obj) == page) {
                    return null;
                }
                List<Object> list = new ArrayList<Object>();
                for (int i = 0; i < 500000; i++) {
                    ReMianPage mg01 = new ReMianPage();
                    mg01.setXm("张坤");
                    mg01.setXb("男");
                    mg01.setCsny(new Date());
//                    mg01.setZp("D:/java/workspace/idea/springboot-bucket/springboot-easypoi/src/main/resources/template/123.png");
                    list.add(mg01);
                }
                return list;
            }
        },10);
        workbook.write(response.getOutputStream());

    }
    /**
     * 大数据导出
     * @return
     * @throws Exception
     */
    @RequestMapping("/bigDataExport01")
    public String bigDataExport01(ModelMap map){
        List<ReMianPage> list = new ArrayList<ReMianPage>();
        Workbook workbook = null;
        Date start = new Date();

        ExportParams params = new ExportParams("2412312", "测试", ExcelType.HSSF);
        params.setFreezeCol(2);
        map.put(BigExcelConstants.CLASS, ReMianPage.class);
        map.put(BigExcelConstants.PARAMS, params);
        //就是我们的查询参数,会带到接口中,供接口查询使用
        map.put(BigExcelConstants.DATA_PARAMS, new HashMap<String,String>());
        map.put(BigExcelConstants.DATA_INTER,excelExportServer);
        return BigExcelConstants.EASYPOI_BIG_EXCEL_VIEW;
    }

    /**
     * 大数据导出
     * @return
     * @throws Exception
     */
    @RequestMapping("/bigDataExport02")
    public void bigDataExport02( HttpServletRequest request,
                                 HttpServletResponse response) {
        ExportParams params = new ExportParams("2412312", "测试", ExcelType.HSSF);
        params.setFreezeCol(2);
        Map map = new HashMap();
        map.put(BigExcelConstants.CLASS, ReMianPage.class);
        map.put(BigExcelConstants.PARAMS, params);
        //就是我们的查询参数,会带到接口中,供接口查询使用
        map.put(BigExcelConstants.DATA_PARAMS, new HashMap<String,String>());
        map.put(BigExcelConstants.DATA_INTER,excelExportServer);
        PoiBaseView.render(map, request, response, BigExcelConstants.EASYPOI_BIG_EXCEL_VIEW);
    }

    @GetMapping("/DownloadPdf")
    public   void DownloadPdf(HttpServletResponse response){

        //1.设置文件ContentType类型，这样设置，会自动判断下载文件类型
        response.setContentType("application/x-download");
        //2.设置文件头：最后一个参数是设置下载文件名(假如我们叫a.pdf)
        // response.setHeader("Content-Disposition", "attachment;fileName="+"a.pdf");


        response.addHeader("Content-Type", "application/x-download");
        response.addHeader("Content-Disposition", "attachment;fileName=a.pdf");
        BusinessData businessData=new BusinessData();
        businessData.setTemplateName("Hello iText! Hello freemarker! Hello jFreeChart!");
        businessData.setFreeMarkerUrl("http://www.zheng-hang.com/chm/freemarker2_3_24/ref_directive_if.html");
        businessData.setITEXTUrl("http://developers.itextpdf.com/examples-itext5");
        businessData.setJFreeChartUrl("http://www.yiibai.com/jfreechart/jfreechart_referenced_apis.html");
        businessData.setImageUrl("D:/java/workspace/idea/springboot-bucket/springboot-easypoi/src/main/resources/template/123.png");
        businessData.setPicUrl("D:/java/workspace/idea/springboot-bucket/springboot-easypoi/src/main/resources/template/123.png");
        List<String> scores=new ArrayList<String>();
        for (int i = 0; i < 100; i++) {

            scores.add("94"+i);

        }
        businessData.setScores(scores);
        PDFUtils pdfUtils=new PDFUtils();
        OutputStream outputStream=pdfUtils.exportToResponse("D:/java/workspace/idea/springboot-bucket/springboot-easypoi/src/main/resources/template/hello.ftl",businessData,response);


    }

}
